from google.appengine.ext import webapp

from src.handlers.live import LiveHandler
from src.handlers.main import MainHandler
from src.handlers.change import ChangeHandler
from src.handlers.init import InitHandler
from src.handlers.sign import SignInHandler, SignOutHandler
from src.handlers.cleaner import CleanerStarter, CleanerRunner
from src.handlers.name import NameChooseHandler
from src.handlers.redirecter import RedirectHandler
from src.handlers.login import LoginHandler
from src.utilities.autoretry import autoretry_datastore_timeouts
import wsgiref.handlers
from google.appengine.ext.webapp.util import run_wsgi_app

def main():
    url_mapping = []
    url_mapping.append(('/', MainHandler))
    url_mapping.append(('/login', LoginHandler))
    url_mapping.append(('/init', InitHandler))
    url_mapping.append(('/live', LiveHandler))
    url_mapping.append(('/change/name', ChangeHandler))
    url_mapping.append(('/name', NameChooseHandler))
    url_mapping.append(('/signIn', SignInHandler))
    url_mapping.append(('/signOut', SignOutHandler))
    
    #url_mapping.append(('/cleaner/start', CleanerStarter))
    #url_mapping.append(('/cleaner/run', CleanerRunner))
    url_mapping.append(('/redirect/(.+)', RedirectHandler))



    application = webapp.WSGIApplication(url_mapping, debug=False)
    run_wsgi_app(application)

    #wsgiref.handlers.CGIHandler().run(application)

if __name__ == '__main__':
    autoretry_datastore_timeouts()
    main()
